<template>
  <!---->
  <el-dialog
    :close-on-click-modal="false"
    title="生成报价"
    :visible.sync="dialogVisible"
    :beforeClose ='handleClose'
    width="400px">
    <div>
      <el-form size="mini" :model="sendForm" label-width="130px"  ref="sendForm" :rules="rules">
        <el-form-item label="报价日期：">
          {{ date }}
        </el-form-item>
        <el-form-item label="采购底价：" prop="purchasePrice">
          <el-input style="width:100px" v-model="sendForm.purchasePrice"></el-input>
        </el-form-item>
        <el-form-item label="可售库存量：" prop="stockNum">
            <el-input v-model="sendForm.stockNum"  style="width:100px"></el-input>
        </el-form-item>
        <el-form-item label="发货日期：" prop="sendDate">
          <el-date-picker
             style="width:130px;"
             v-model="sendForm.sendDate"
             :picker-options="pickerOptions1"
             value-format="yyyy-MM-dd"
             type="date"
             placeholder="选择日期时间：">
        </el-date-picker>
        </el-form-item>
        <el-form-item label="价格类型：">
            <el-select v-model="sendForm.priceType" style="width:100px;">
              <el-option  label="滞销" value="滞销"></el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="备注：" >
          <el-input v-model="sendForm.priceRemark" style="width:100px;"></el-input>
        </el-form-item>
      </el-form>
    </div>
    <span slot="footer" class="dialog-footer">
          <el-button @click="handleClose">取 消</el-button>
          <el-button type="primary" @click="handleConfirm" :loading="btnLoading">确认</el-button>
      </span>
  </el-dialog>
</template>
<script>
import {goodsPricePublish} from '@/api/allInLine/inquiry'
import { mapGetters } from 'vuex'
import { Message } from 'element-ui';

const defaultSendForm={
  goodsDetailId : '', //规格商品ID
  sendAreaId : '',  //发货区域ID(修改时，非必填)
  fromCompany : "", //供货方
  warehouseName : "", //发货仓库
  stockNum : '',  //库存
  payTypes : "", //结算方式(修改时，非必填)
  purchasePrice : '', //采购底价
  sendDate : "", //发货日期
  sendTypes : "", //发货方式(修改时，非必填)
  buyMinNum : '', //起订量(修改时，非必填)
  priceType : "", //价格类型(滞销、紧俏、平稳)(修改时，非必填)
  priceRemark : "", //备注(修改时，非必填)
  deliveryType : "", //发货类型(公司发货、采购发货、客户自提)
  priceTime:''
};

export default {
  name: "index",
  data(){
    return {
      dialogVisible:false,
      btnLoading:false,
      date:'',
      sendForm:JSON.parse(JSON.stringify(defaultSendForm)),
      rules:{purchasePrice:[{required:true,message:'请输入采购底价',trigger:'blur'}],
      sendDate:[{required:true,message:'请选择发货日期',trigger:'change'}],
      stockNum:[{required:true,message:'请输入可售库存量',trigger:'blur'}]},
      options:[],
      diQuIds:[],
      title:'',
      pickerOptions1: {
        disabledDate(time) {
          return time.getTime() < Date.now()  - 8.64e7;
        },
      },
    }
  },
  computed: {
    ...mapGetters([
      'name',
      'mobile',
      'userId'
    ]),
  },
  components : {

  },
  created() {

  },
  filters: {

  },
  methods:{

    //显示
    showPop(item){
      console.log(1);
      this.sendForm = JSON.parse(JSON.stringify(defaultSendForm))
      const today = new Date();
      const year = today.getFullYear();
      const month = ('0' + (today.getMonth() + 1)).slice(-2); // 加1是因为月份从0开始计数，slice(-2)用于保留两位数
      const day = ('0' + today.getDate()).slice(-2);
      this.date = `${year}-${month}-${day}`
      if(item){
      this.sendForm.goodsDetailId =item.goodsDetailId?item.goodsDetailId:'' , //规
      this.sendForm.sendAreaId =item.areaId?item.areaId:'' , //规
      this.sendForm.fromCompany =item.fromCompany?item.fromCompany:'' , //规
      this.sendForm.warehouseName =item.warehouseName?item.warehouseName:'' , //规
      this.sendForm.stockNum =item.stockNum?item.stockNum:'' , //规
      this.sendForm.payTypes =item.payTypes?item.payTypes:'' , //规
      this.sendForm.purchasePrice =item.purchasePrice?item.purchasePrice:'' , //规
      this.sendForm.sendDate =item.sendDate?item.sendDate:'' , //规
      this.sendForm.sendTypes =item.sendTypes?item.sendTypes:'' , //规
      this.sendForm.buyMinNum =item.buyMinNum?item.buyMinNum:'' , //规
      this.sendForm.priceType =item.priceType?item.priceType:'' , //规
      this.sendForm.priceRemark =item.priceRemark?item.priceRemark:'' , //规
      this.sendForm.deliveryType =item.deliveryType?item.deliveryType:'' , //规
      this.sendForm.priceTime =item.priceTime?item.priceTime:''  //规
      }
      this.dialogVisible = true;

    },
    //关闭
    handleClose(){
      this.$refs.sendForm.resetFields()
      this.sendForm = JSON.parse(JSON.stringify(defaultSendForm))
      this.dialogVisible = false;
    },

    //确认
    handleConfirm(){
      this.$refs.sendForm.validate(valid=>{
        if(valid){
          this.btnLoading = true
          const data = JSON.parse(JSON.stringify(this.sendForm))
          console.log(data);
          goodsPricePublish({goodsList:[data]}).then(res=>{
          Message.success('生成报价成功')
          this.btnLoading = false
          this.dialogVisible = false;
          this.$refs.sendForm.resetFields()
          this.sendForm = JSON.parse(JSON.stringify(defaultSendForm))
       }).catch(()=>{
          this.btnLoading = false
      })
        }
      })

    },
  },
}
</script>

<style  lang="scss">

</style>
